import { AfterViewInit, Component, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Planet, SwitchModes } from '@worktile/planet';
// import  { loadMicroApp ,MicroApp, initGlobalState , registerMicroApps, start } from 'qiankun' ;
import { Subscriber, Subscription } from 'rxjs';
import microApps from '../../../microApp.js' ;

@Component({
  selector: 'app-qiankun',
  templateUrl: './qiankun.component.html',
  styleUrls: ['./qiankun.component.less']
})
export class QiankunComponent implements OnInit, OnDestroy , AfterViewInit{

  routerListener1: Subscription ;
  microAction: any;
  microApp: any;
  constructor(private router: ActivatedRoute,
              private route: Router,
              private planet: Planet) { }

  ngOnInit(): void {
  
    
  }

ngAfterViewInit(): void {
  // this.initPlanet() ;
  // this.initSpa() ;
}  

  initSpa(){
    // this.microApp = loadMicroApp({
    //   name: 'app1',
    //   entry: '//localhost:1400',
    //   container:'#micro',
    //   props: { brand: 'qiankun' },
    // });
  }

  initPlanet(): any {
    this.planet.setOptions({
      switchMode: SwitchModes.coexist ,
      errorHandler: (err) => {
        console.error(`加载资源失败，
        error:`, err) ;
      }
    });
  
    this.planet.registerApps([
      {
        name: 'app1',
        hostParent: '#app1-container',
        hostClass: 'thy-layout',
        routerPathPrefix: '/angular9',
        resourcePathPrefix: '//localhost:1400/',
        preload: true,
        scripts: [
            'main.js'
        ],
        styles: [
            'styles.css'
        ]
      }
    ]);
    this.planet.start();
  
    return  ;
  }
  ngOnDestroy(): void {

  }

}
